package com.imu.purse.modules.trade.dao;

import java.util.List;
import org.apache.ibatis.annotations.Select;
import com.imu.purse.modules.trade.entity.UserIpEntity;
import com.imu.core.base.BaseMapper;

/**
 * 
 * @author sunhongwei
 * @email sunhongwei@jshijian.com
 * @date 2018-07-26 11:31:20
 * Copyright (c) 2017 武汉极时间科技有限公司 版权所有 
 * Jshijian aloha CO.,LTD. All Rights Reserved. 
 */
public interface UserIpMapper extends BaseMapper<UserIpEntity>
{
	/**
     * 分页查询
     * @return
     */
	@Select({
		"<script>",
		    "SELECT id,",
					"ip, ",
					"time_create",
		    "FROM imu_user_ip ",
		    "WHERE 1 = 1",
			"<when test = 'ip != null'>",
		    	"AND `ip` = #{ip}",
		    "</when>",
			"<when test = 'timeCreate != null'>",
		    	"AND `time_create` = #{timeCreate}",
		    "</when>",
		    "<when test = 'stimeStr != null'>",
		    	"AND time_create &gt;= #{stimeStr}",
		    "</when>",
		    "<when test = 'etimeStr != null'>",
				"AND time_create &lt;= #{etimeStr}",
			"</when>",
		    "ORDER BY time_create DESC",
    	"</script>"
	})
    public List<UserIpEntity> findByPage(final UserIpEntity entity);

	/**
	 * 根据手机号码和类型获取在指定时间内短信调用的数量
	 * @param entity
	 * @return
	 */
	@Select(
		{
			"<script>",
				"select count(1) from imu_user_ip where ip = #{ip} ",
					"<if test='unit == 1'> ",
						" and time_create &gt;= DATE_ADD(#{timeCreate},INTERVAL #{interval} MINUTE)",
					"</if>",
				    "<if test='unit == 2'>",
						" and time_create &gt;= DATE_ADD(#{timeCreate},INTERVAL #{interval} hour)",
				    "</if>",
					"<if test='unit == 3'>",
						" and time_create &gt;= DATE_ADD(#{timeCreate},INTERVAL #{interval} day)",
					"</if>",
					" and time_create &lt;= #{timeCreate}",
			"</script>"
		}
	)
	public int queryCountByPhAndTime(final  UserIpEntity entity);
}
